package org.springframework.util;

import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class AntPathMatcher
  implements PathMatcher
{
  public static final String DEFAULT_PATH_SEPARATOR = "/";
  private static final Pattern VARIABLE_PATTERN = Pattern.compile("\\{[^/]+?\\}");
  private String pathSeparator = "/";

  private boolean matchStrings(String paramString1, String paramString2, Map<String, String> paramMap)
  {
    return new AntPathStringMatcher(paramString1, paramString2, paramMap).matchStrings();
  }

  public String combine(String paramString1, String paramString2)
  {
    if ((!StringUtils.hasText(paramString1)) && (!StringUtils.hasText(paramString2)))
      paramString2 = "";
    do
    {
      do
        return paramString2;
      while (!StringUtils.hasText(paramString1));
      if (!StringUtils.hasText(paramString2))
        return paramString1;
    }
    while (match(paramString1, paramString2));
    if (paramString1.endsWith("/*"))
    {
      if (paramString2.startsWith("/"))
        return paramString1.substring(0, -1 + paramString1.length()) + paramString2.substring(1);
      return paramString1.substring(0, -1 + paramString1.length()) + paramString2;
    }
    if (paramString1.endsWith("/**"))
    {
      if (paramString2.startsWith("/"))
        return paramString1 + paramString2;
      return paramString1 + "/" + paramString2;
    }
    int i = paramString1.indexOf('.');
    if (i == -1)
    {
      if ((paramString1.endsWith("/")) || (paramString2.startsWith("/")))
        return paramString1 + paramString2;
      return paramString1 + "/" + paramString2;
    }
    String str1 = paramString1.substring(0, i);
    String str2 = paramString1.substring(i);
    int j = paramString2.indexOf('.');
    String str3;
    String str4;
    String str5;
    if (j != -1)
    {
      str3 = paramString2.substring(0, j);
      str4 = paramString2.substring(j);
      if (!str1.endsWith("*"))
        break label363;
      str5 = str3;
      label318: if (!str2.startsWith("*"))
        break label370;
    }
    label363: label370: for (String str6 = str4; ; str6 = str2)
    {
      return str5 + str6;
      str3 = paramString2;
      str4 = "";
      break;
      str5 = str1;
      break label318;
    }
  }

  protected boolean doMatch(String paramString1, String paramString2, boolean paramBoolean, Map<String, String> paramMap)
  {
    if (paramString2.startsWith(this.pathSeparator) != paramString1.startsWith(this.pathSeparator))
      return false;
    String[] arrayOfString1 = StringUtils.tokenizeToStringArray(paramString1, this.pathSeparator);
    String[] arrayOfString2 = StringUtils.tokenizeToStringArray(paramString2, this.pathSeparator);
    int i = 0;
    int j = -1 + arrayOfString1.length;
    int k = 0;
    int m = -1 + arrayOfString2.length;
    while (true)
    {
      if ((i > j) || (k > m));
      String str2;
      do
      {
        if (k <= m)
          break label241;
        if (i <= j)
          break label168;
        if (!paramString1.endsWith(this.pathSeparator))
          break;
        return paramString2.endsWith(this.pathSeparator);
        str2 = arrayOfString1[i];
      }
      while ("**".equals(str2));
      if (!matchStrings(str2, arrayOfString2[k], paramMap))
        return false;
      i++;
      k++;
    }
    return !paramString2.endsWith(this.pathSeparator);
    label168: if (!paramBoolean)
      return true;
    if ((i == j) && (arrayOfString1[i].equals("*")) && (paramString2.endsWith(this.pathSeparator)))
      return true;
    for (int i9 = i; ; i9++)
    {
      if (i9 > j)
        return true;
      if (!arrayOfString1[i9].equals("**"))
        return false;
    }
    label241: if (i > j)
      return false;
    String str1;
    if ((!paramBoolean) && ("**".equals(arrayOfString1[i])))
    {
      return true;
      str1 = arrayOfString1[j];
      if (str1.equals("**"))
        label286: if (k <= m)
          break label396;
    }
    for (int i8 = i; ; i8++)
    {
      if (i8 > j)
      {
        return true;
        if (!matchStrings(str1, arrayOfString2[m], paramMap))
          return false;
        j--;
        m--;
        if (i > j)
          break label286;
        if (k <= m)
          break;
        break label286;
      }
      if (!arrayOfString1[i8].equals("**"))
        return false;
    }
    int i1 = -1;
    int i2 = i + 1;
    label377: if (i2 > j)
    {
      if (i1 != i + 1)
        break label449;
      i++;
      if ((i != j) && (k <= m))
        break label565;
    }
    label384: label396: for (int n = i; ; n++)
    {
      if (n > j)
      {
        return true;
        if (arrayOfString1[i2].equals("**"))
        {
          i1 = i2;
          break label384;
        }
        i2++;
        break label377;
        label449: int i3 = -1 + (i1 - i);
        int i4 = 1 + (m - k);
        int i5 = -1;
        int i6 = 0;
        if (i6 > i4 - i3)
          label483: if (i5 == -1)
            return false;
        else
          for (int i7 = 0; ; i7++)
          {
            if (i7 >= i3)
            {
              i5 = k + i6;
              break label483;
            }
            if (!matchStrings(arrayOfString1[(1 + (i + i7))], arrayOfString2[(i7 + (k + i6))], paramMap))
            {
              i6++;
              break;
            }
          }
        i = i1;
        k = i5 + i3;
        break label396;
        label565: break;
      }
      if (!arrayOfString1[n].equals("**"))
        return false;
    }
  }

  public String extractPathWithinPattern(String paramString1, String paramString2)
  {
    String[] arrayOfString1 = StringUtils.tokenizeToStringArray(paramString1, this.pathSeparator);
    String[] arrayOfString2 = StringUtils.tokenizeToStringArray(paramString2, this.pathSeparator);
    StringBuilder localStringBuilder = new StringBuilder();
    int i = 0;
    int j = 0;
    if (j >= arrayOfString1.length);
    for (int k = arrayOfString1.length; ; k++)
    {
      if (k >= arrayOfString2.length)
      {
        return localStringBuilder.toString();
        String str = arrayOfString1[j];
        if (((str.indexOf('*') > -1) || (str.indexOf('?') > -1)) && (arrayOfString2.length >= j + 1))
        {
          if ((i > 0) || ((j == 0) && (!paramString1.startsWith(this.pathSeparator))))
            localStringBuilder.append(this.pathSeparator);
          localStringBuilder.append(arrayOfString2[j]);
          i++;
        }
        j++;
        break;
      }
      if ((i > 0) || (k > 0))
        localStringBuilder.append(this.pathSeparator);
      localStringBuilder.append(arrayOfString2[k]);
    }
  }

  public Map<String, String> extractUriTemplateVariables(String paramString1, String paramString2)
  {
    LinkedHashMap localLinkedHashMap = new LinkedHashMap();
    doMatch(paramString1, paramString2, true, localLinkedHashMap);
    return localLinkedHashMap;
  }

  public Comparator<String> getPatternComparator(String paramString)
  {
    return new AntPatternComparator(paramString, null);
  }

  public boolean isPattern(String paramString)
  {
    return (paramString.indexOf('*') != -1) || (paramString.indexOf('?') != -1);
  }

  public boolean match(String paramString1, String paramString2)
  {
    return doMatch(paramString1, paramString2, true, null);
  }

  public boolean matchStart(String paramString1, String paramString2)
  {
    return doMatch(paramString1, paramString2, false, null);
  }

  public void setPathSeparator(String paramString)
  {
    if (paramString != null);
    while (true)
    {
      this.pathSeparator = paramString;
      return;
      paramString = "/";
    }
  }

  private static class AntPatternComparator
    implements Comparator<String>
  {
    private final String path;

    private AntPatternComparator(String paramString)
    {
      this.path = paramString;
    }

    private int getPatternLength(String paramString)
    {
      return AntPathMatcher.VARIABLE_PATTERN.matcher(paramString).replaceAll("#").length();
    }

    private int getWildCardCount(String paramString)
    {
      if (paramString.endsWith(".*"))
        paramString = paramString.substring(0, -2 + paramString.length());
      return StringUtils.countOccurrencesOf(paramString, "*");
    }

    public int compare(String paramString1, String paramString2)
    {
      if ((paramString1 == null) && (paramString2 == null))
        return 0;
      if (paramString1 == null)
        return 1;
      if (paramString2 == null)
        return -1;
      boolean bool1 = paramString1.equals(this.path);
      boolean bool2 = paramString2.equals(this.path);
      if ((bool1) && (bool2))
        return 0;
      if (bool1)
        return -1;
      if (bool2)
        return 1;
      int i = getWildCardCount(paramString1);
      int j = getWildCardCount(paramString2);
      int k = StringUtils.countOccurrencesOf(paramString1, "{");
      int m = StringUtils.countOccurrencesOf(paramString2, "{");
      int n = i + k;
      int i1 = j + m;
      if (n != i1)
        return n - i1;
      int i2 = getPatternLength(paramString1);
      int i3 = getPatternLength(paramString2);
      if (i2 != i3)
        return i3 - i2;
      if (i < j)
        return -1;
      if (j < i)
        return 1;
      if (k < m)
        return -1;
      if (m < k)
        return 1;
      return 0;
    }
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     org.springframework.util.AntPathMatcher
 * JD-Core Version:    0.6.2
 */